define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'product/vip/index' + location.search,
                    add_url: 'product/vip/add',
                    edit_url: 'product/vip/edit',
                    del_url: 'product/vip/del',
                    multi_url: 'product/vip/multi',
                    import_url: 'product/vip/import',
                    table: 'product_vip',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                escape:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'member_id', title: __('Member_id')},
                        {field: 'cname', title: __('会员类型')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate',cellStyle: {css: {
                                    "max-width": "300px",
                                }}, title: __('Operate'), buttons:[
                                {
                                    name:'list',
                                    text:__("申请会员判断"),
                                    title:__("申请会员判断"),
                                    url:'product/vip/vip_panduan/type/11',
                                    classname: 'btn btn-xs btn-warning btn-magic btn-ajax',
                                    icon: '',
                                    confirm: '确定要通过申请吗',
                                    refresh: true,
                                    hidden: function (row) {
                                        if (row.status == 0) {
                                            return false;
                                        } else {
                                            return true;
                                        }
                                    },
                                }
                            ],table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
